package com.bm.controller;

import com.bm.Result.CodeEnum;
import com.bm.Result.Result;
import com.bm.Vo.Repair.PetDetailVo;
import com.bm.model.EjyyPet;
import com.bm.query.Pet.*;
import com.bm.service.EjyyPetService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 86134
 * @version 1.0
 * @description TODO
 * @date 2024/3/1 20:38
 */
@RestController
@Api(tags = "宠物相关接口")
public class PetController {
    @Autowired
    private EjyyPetService ejyyPetService;

    @PostMapping("/pet/list")
    @ApiOperation(value = "分页查询所有宠物")
    public Result PetList(@RequestBody PetQuery pageQuery) {
        PageInfo<EjyyPet> ejyyPets = ejyyPetService.petListByPage(pageQuery);
        return Result.OK(ejyyPets);
    }

    @PostMapping("/pet/create")
    @ApiOperation(value = "新增宠物信息")
    public Result CreatePet(@RequestBody CreatePetQuery petQuery) {
        boolean flag = ejyyPetService.createPet(petQuery);
        return flag ? Result.OK(CodeEnum.OK) : Result.FAIL();
    }

    @PostMapping("/pet/detail")
    @ApiOperation(value = "宠物详情信息")
    public Result PetDetail(@RequestBody PetDetailQuery petDetailQuery) {
        PetDetailVo petDetailVo = ejyyPetService.petDetailById(petDetailQuery);
        return Result.OK(petDetailVo);
    }

    @PostMapping("/pet/license/{id}")
    @ApiOperation(value = "更新宠物登记信息")
    public Result PetLicense(@PathVariable Long id,@RequestBody PetLicenseQuery petLicenseQuery){
        boolean flag = ejyyPetService.updatePetLicense(id,petLicenseQuery);
        return flag ? Result.OK(200,"更新宠物登记成功") : Result.FAIL();
    }

    @PostMapping("/pet/vaccinate/{id}")
    @ApiOperation(value = "新增宠物打疫苗信息")
    public Result PetVaccinate(@PathVariable Long id,
                               @RequestBody PetVaccinateQuery petVaccinateQuery){
        boolean flag = ejyyPetService.InsertPetVaccinate(id,petVaccinateQuery);
        return flag ? Result.OK(200,"新增成功"):Result.FAIL("新增失败");
    }




}
